#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
  //write 
  //FILE *fp = fopen("file.txt", "w");
  //if(NULL == fp){
  //  perror("fopen error");
  //  return 1;
  //}
  //
  //const char * msg = "hello yumoz\n";
  //int count = 5;
  //while(count--){
  //  fwrite(msg, strlen(msg), 1, fp);//fwrite msg -> fp 
  //}
  //fclose(fp);

  // read file 
  FILE *fp = fopen("file.txt", "r");
  if(!fp){
    perror("fopen error\n");
  } 

  char buf[1024];
  const char *msg = "hello moyuz\n";
  while(1){
    ssize_t s = fread(buf, 1, strlen(msg), fp);
    if(s > 0){
      buf[s] = 0;
      printf("%s", buf);
    }
    if(feof(fp)){
      break;
    }
  }
  fclose(fp);

  // test 
  //int ct = 4;
  //while(ct>0){
  //  fputs("hello yumoz\n",stdout);
  //  ct--;
  //}
  // test 3
  //int count = 6;
  //char buffer[64];
  //while(count){
  //  fgets(buffer,sizeof(buffer),fp);
  //  printf("%s",buffer);
  //  count--;
  //}

  // test 2
  //int count = 5;
  //while(count){
  //  fputs("hello yumoz nice \n",fp);
  //  count--;
  //}
  //fclose(fp);
 
  //FILE *fp = fopen("myfile","w");
  //if(!fp){
  //  printf("fopen error");
  //}
  //const char *msg = "hello yumoz\n";
  //int count = 5;
  //while(count--){
  //  fwrite(msg,strlen(msg),1,fp);
  //}

  //fclose(fp);

  return 0;
}
